<template>
	
	<div>
		<el-divider></el-divider>
		<table  style="margin-top: 0.9375rem; margin-bottom: 20px; " >
		  		   <i class="el-icon-search" style="margin-left: 5px;  color: cadetblue;" >筛选查询</i>
		  		    <span style="margin-left:80px;">状态:&nbsp;</span>
		  		    <el-select v-model="getStoreParam.storeStatus" style=" width: 100px;" placeholder="请选择">
		  		        <el-option label="全部" value=""></el-option>
		  		         <el-option label="停用" value="0"></el-option>
		  				 <el-option label="启用" value="1"></el-option>
		  		     </el-select>
		  		      <span  style="margin-left:50px;">模糊查询:&nbsp;</span>
		  			  <el-input v-model="getStoreParam.storeName" style=" width: 100px;" placeholder="门店名称"></el-input>
					  <el-input v-model="getStoreParam.storePeople" style=" width: 100px;" placeholder="联系人名称"></el-input>
					  <el-input v-model="getStoreParam.storePhone" style=" width: 100px;" placeholder="手机号"></el-input>
		  			  &nbsp; &nbsp; &nbsp; &nbsp;<el-button type="primary" class="el-icon-search" @click="getAllStore">查询</el-button>
		</table>
		<table border="0px">
			<el-row>
				<i class="el-icon-s-grid" style="margin-left: 5px;">数据列表</i>
				<el-button type="primary" @click="addHouse=true" style="margin-left: 760px;">新增</el-button>
		
			</el-row>
		
		</table>
		<el-divider></el-divider>
		
		
		
		
		<el-table  :data="storeDatas" tooltip-effect="dark" style="width: 100%" >
			
			<el-table-column prop="storeId" label="编号" width="130px">
			</el-table-column>
			<el-table-column prop="storeName" label="门店名称" width="130px">
			</el-table-column>
			<el-table-column prop="storePeople" label="联系人" width="130px">
			</el-table-column>
			<el-table-column prop="storePhone" label="手机号" width="130px">
			</el-table-column>
			<el-table-column prop="storeAddress"  label="地址" width="130px">
			</el-table-column>
			<el-table-column prop="warehouses"  label="管辖仓库" width="130px">
			</el-table-column>
			<el-table-column prop="storeStatus"  label="状态" width="130px" :formatter="forcode">
			</el-table-column>
			<el-table-column prop="name" label="操作" width="250">
					<template slot-scope="scope">
						<el-button type="text" @click="setStore(scope.row)">修改</el-button>
						<el-button type="text" @click="delHouse(scope.row.storeId)">删除</el-button>
					</template>
			</el-table-column>
		</el-table>
		<div>
			<el-pagination :current-page="currentPage" @current-change="changePage" background layout="prev, pager, next"
			 :total="total" :page-size="5">
			</el-pagination>
		</div>
		
		
		
		
		
		
		<el-dialog title="新增门店" :visible.sync="addHouse" @close="clearfrom">
			<el-form :model="insertStore" label-width="100px" class="demo-ruleForm">
				<el-row>
					<el-form-item label="门店名称"  style="width: 400px;">
						<el-input v-model="insertStore.storeName"></el-input>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="联系人"  style="width: 400px;">
						<el-input v-model="insertStore.storePeople"></el-input>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="联系人电话"  style="width: 400px;">
						<el-input v-model="insertStore.storePhone"></el-input>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="地址" style="width: 400px;">
						<el-input v-model="insertStore.storeAddress"></el-input>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="状态"  style="width: 200px;">
						<el-select v-model="insertStore.storeStatus" placeholder="请选择" style="width: 12.5rem" >
							<el-option label="启用" value="0"></el-option>
							<el-option label="停用" value="1"></el-option>
						</el-select>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="仓库选择" style="width: 400px;">
					</el-form-item>
				</el-row>
			</el-form>
			<el-transfer
			  filterable
			  v-model="aaa"
			  :data="bigSorts"
				>
			</el-transfer>
		<div align="center">
				<el-button @click="clearfrom">清空</el-button>
				<el-button type="primary" @click="addStore">保存</el-button>
			</div>
		</el-dialog>
		
		
		
		
		<el-dialog title="修改门店" :visible.sync="updateStore" @close="clearfrom">
			<el-form :model="updateStoreParam" label-width="100px" class="demo-ruleForm">
				<el-row>
					<el-form-item label="编号"  style="width: 400px;">
						<el-input v-model="updateStoreParam.storeId" :disabled="true">{{updateStoreParam.storeId}}</el-input>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="门店名称"  style="width: 400px;">
						<el-input v-model="updateStoreParam.storeName">{{updateStoreParam.storeName}}</el-input>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="联系人"  style="width: 400px;">
						<el-input v-model="updateStoreParam.storePeople">{{updateStoreParam.storePeople}}</el-input>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="联系人电话"  style="width: 400px;">
						<el-input v-model="updateStoreParam.storePhone">{{updateStoreParam.storePhone}}</el-input>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="地址" style="width: 400px;">
						<el-input v-model="updateStoreParam.storeAddress">{{updateStoreParam.storeAddress}}</el-input>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="状态"  style="width: 200px;">
						<el-select v-model="updateStoreParam.storeStatus" placeholder="请选择" style="width: 12.5rem">
							<el-option label="启用" value="0"></el-option>
							<el-option label="停用" value="1"></el-option>
						</el-select>
					</el-form-item>
				</el-row>
				
				<el-row>
					<el-form-item label="仓库选择" style="width: 400px;">
					</el-form-item>
				</el-row>
				
				
			</el-form>
		
			<el-transfer
			  filterable
			  v-model="ccc"
			  :data="bigSorts"
			
				>
			</el-transfer>
		
			<div align="center">
				<el-button @click="clearfrom">清空</el-button>
				<el-button type="primary" @click="updateStoress">保存</el-button>
			</div>
		
		</el-dialog>
		
		
		
		
		
		
		
		
		
		
	</div>
	
</template>

<script>
	export default {
		name:'store',
		data(){
			return {
				total:0,
				currentPage:1,
				updateStore:false,
				ccc:[],
				aaa:[],
				bigSorts:[],
				updateStoreParam:{
					storeId:null,
					storeName:null,
					storePeople:null,
					storePhone:null,
					storeAddress:null,
					storeStatus:null,
					num:[]
				},
				insertStore:{
					storeName:null,
					storePeople:null,
					storePhone:null,
					storeAddress:null,
					storeStatus:null,
					name:[]
				},
				addStoreParam:{
					storeName:null,
					storePeople:null,
					storePhone:null,
					storeAddress:null,
					storeStatus:null,
					
					
				},
				addHouse:false,
				getStoreParam:{
					    storeStatus:null,
					    storeName:null,
					    storePeople:null,
					    storePhone:null,
					    pageParam:{
							indexPage:1,
							size:10
						}
				},
				storeDatas:[],
				storeData:{
					storeId:null,
					storeName:null,
					storePeople:null,
					storePhone:null,
					storeAddress:null,
					warehouses:null,
					storeStatus:null
				}
			}
		},
		
	
		
		methods:{
			
			changePage(index){
						   this.getStoreParam.pageParam.indexPage=index;
						   this.getAllStore();
			},
			updateStoress(){
				this.updateStoreParam.num=this.ccc
				
				this.$http.post("/pawnbackgroundsystem/store/updeteStore",this.updateStoreParam).then((resp) => {
									
									if (resp.data.coed == '2002') {
										this.$message({
												message: '修改成功',
												type: 'success'
											});
											this.updateStore=false;
											this.getAllStore();
										}
													
										
									
								})
				
				
				
				
			},
			setStore(row){
				this.updateStore=true;
				this.ccc=[],
				this.updateStoreParam.storeId=row.storeId,
				this.updateStoreParam.storeName=row.storeName,
				this.updateStoreParam.storePeople=row.storePeople,
				this.updateStoreParam.storePhone=row.storePhone,
				this.updateStoreParam.storeAddress=row.storeAddress,
				this.updateStoreParam.storeStatus=row.storeStatus+"",
				this.updateStoreParam.name=row.num,
				this.$http.get("/pawnbackgroundsystem/store/getStoreName?storeId="+row.storeId).then((resp) => {
									
									if (resp.data.coed == '2002') {
										
													for(var i=0;i<resp.data.data.length;i++){
														this.ccc.push(parseInt(resp.data.data[i]))
													}
										
									}
								})
				
				
				
				
				
				
			},
			
			
			delHouse(storeId){
						  
						   this.$http.get("/pawnbackgroundsystem/store/delStore?storeId="+storeId).then((resp) => {
						   					
						   					if (resp.data.coed == '2002') {
						   						this.$message({
						   							message: '删除成功',
						   							type: 'success'
						   						});
						   						this.getAllStore();
						   					}
						   				})
			},
			selectHouse(){
				this.$http.get("pawnbackgroundsystem/warehouse/getAllHouse").then(resp=>{
					
					this.bigSorts=resp.data.data
				})
			},
			addStore(){
				
				this.insertStore.name=this.aaa;
				this.$http.post("pawnbackgroundsystem/store/insertStore",this.insertStore).then(resp=>{
					if (resp.data.coed == '2002') {
						this.addHouse=false;
						this.getAllStore();
					}
				})
				
				
			},
			clearfrom(){
				this.insertStore={
					storeName:null,
					storePeople:null,
					storePhone:null,
					storeAddress:null,
					storeStatus:null,
					name:[]
				}
				this.aaa=[]
				
			},
			forcode(row){
				return row.storeStatus==1?'停用':'启用';
			},
			getAllStore(){
				this.storeDatas=[]
				this.$http.post("/pawnbackgroundsystem/store/selectStore",this.getStoreParam).then(resp=>{
					
					var stores=resp.data.data.records
					for(var i=0;i<stores.length;i++){
						this.storeData={
										storeId:stores[i].storeId,
										storeName:stores[i].storeName,
										storePeople:stores[i].storePeople,
										storePhone:stores[i].storePhone,
										storeAddress:stores[i].storeAddress,
										warehouses:'',
										storeStatus:stores[i].storeStatus
									}
						for(var a=0;a<stores[i].warehouses.length;a++){
							this.storeData.warehouses=stores[i].warehouses[a].warehouseName+" "+this.storeData.warehouses;
						}
						this.storeDatas.push(this.storeData);
					}
					this.currentPage=resp.data.data.pages;
					// indePage
					this.total = resp.data.data.total;
					
				})
			}
		},
		created(){
			this.getAllStore()
			this.selectHouse()
		}
	}
	
</script>

<style>
	
</style>